/*
 ============================================================================
 Name		: VibraMassagerView.cpp
 Author	  : 
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CVibraMassagerView implementation
 ============================================================================
 */
#include <aknviewappui.h>
#include "VibraMassagerView.h"
#include "LemonAssistant.hrh"
#include <LemonAssistant.rsg>
#include "LemonAssistantAppUi.h"

CVibraMassagerView::CVibraMassagerView()
	{
	// No implementation required
	iContainer = NULL;
	}

CVibraMassagerView::~CVibraMassagerView()
	{
	DoDeactivate();
	}

CVibraMassagerView* CVibraMassagerView::NewLC()
	{
	CVibraMassagerView* self = new (ELeave) CVibraMassagerView();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

CVibraMassagerView* CVibraMassagerView::NewL()
	{
	CVibraMassagerView* self = CVibraMassagerView::NewLC();
	CleanupStack::Pop(); // self;
	return self;
	}

void CVibraMassagerView::ConstructL()
	{
	BaseConstructL(R_VIBRA_MASSAGER_VIEW);
	}

TUid CVibraMassagerView::Id() const
	{
	return TUid::Uid(ELemonAssistantAppViewVibraMassager);
	}

void CVibraMassagerView::HandleCommandL(TInt aCommand)
	{
	switch (aCommand)
		{
		case EAknSoftkeyBack:
			AppUi()->ActivateLocalViewL(TUid::Uid(ELemonAssistantAppViewMain));
			break;
		case ECommandOperateOpen:
			STATIC_CAST(CLemonAssistantAppUi*,CEikonEnv::Static()->AppUi())
						->SetCommandSetL(R_VIBRA_MASSAGER_OPTIONS_SET_BACK_CLOSE);
			iContainer->Vibra();			
			break;
		case ECommandOperateClose:
			STATIC_CAST(CLemonAssistantAppUi*,CEikonEnv::Static()->AppUi())
						->SetCommandSetL(R_VIBRA_MASSAGER_OPTIONS_SET_BACK_OPEN);
			iContainer->Vibra();			
			break;
		default:
			AppUi()->HandleCommandL(aCommand);
		}
	}

void CVibraMassagerView::HandleStatusPaneSizeChange()
	{
	if (iContainer != NULL)
		iContainer->SetRect(ClientRect());
	}

/**
 * 
 * */
void CVibraMassagerView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
		TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
	{
	if (iContainer == NULL)
		{
		iContainer = CVibraMassagerContainer::NewL(ClientRect());
		iContainer->SetMopParent(this);
		AppUi()->AddToStackL(*this, iContainer);

		//add your init code ...

		}
	}
void CVibraMassagerView::DoDeactivate()
	{
	if (iContainer != NULL)
		{
		AppUi()->RemoveFromViewStack(*this, iContainer);
		delete iContainer;
		iContainer = NULL;
		}
	}
